"use strict";
let core, config, logger, serviceName = 'sdk', client, qs = require('querystring');
let sdk = {
  assert: (error) => {
    if (error) {
      logger.error(error);
      throw '[' + serviceName + '] ' + error;
    }
  },
  init: (name, c) =>  new Promise((callback) => {
    serviceName = name;
    core = c;
    logger = core.getLogger(serviceName);
    config = core.getConfig(serviceName);
    client = require('axios').create({
      baseURL: config.apiAddr,
    })
    callback();
  }),
  getClent: () => client,
  // 关闭充电
  endCharging: (params) => client.get(`/api/Fault/Send?${qs.stringify(params)}`),
  //
  startCharging: (params) => client.get(`/api/Fault/check?${qs.stringify(params)}`),
  report: (serial, params) => client.get(`/api/Tasks/fault?serial=${serial}&code=${JSON.stringify(params)}`),

  checkBalance: (charging) => client.get(`/api/Tasks/judge?eqnub=${charging}`),

  timeout: (charging) => client.get(`/api/Mtce/timeout?eqnub=${charging}`),
};

module.exports = sdk;
